#include "dos.h"
#include "stdio.h"
#include "graphics.h"
#include "process.h"
#include "bios.h"
#ifndef TOV_H
#define TOV_H
void init256(int vmode)
{
	union REGS r;
	r.h.ah=0;
	r.h.al=vmode;
	int86(0x10,&r,&r);
}
void selectpage(register char page)
{
	union REGS r;
	r.x.ax=0x4f05;
	r.x.bx=0;
	r.x.dx=page;
	int86(0x10,&r,&r);
}
unsigned char set_SVGA_mode(int vmode)
{
	union REGS r;
	r.x.ax=0x4f02;
	r.x.bx=vmode;
	int86(0x10,&r,&r);
	return(r.h.ah);
}
unsigned int get_SVGA_mode()
{
	union REGS r;
	r.x.ax=0x4f03;
	int86(0x10,&r,&r);
	return(r.x.bx);
}
void sysgmode(int *gdriver,int *gmode)
{
	printf("%d:%d_",*gdriver,*gmode);
	switch(*gdriver)
	{
		case 1:
			printf("CGA:CGA");
			if(*gmode<4)
				printf("C%d\nC%d:320*200\n",*gmode,*gmode);
			else if(*gmode==4)
				printf("HI\nC4:640*200\n");
			else
				printf("?\nUNKNOWN\n");
			break;
		case 2:
			printf("MCGA:MCGA");
			if(*gmode<4)
				printf("C%d\nC%d:320*200\n",*gmode,*gmode);
			else if(*gmode==4)
				printf("MED\n2:640*200\n");
			else if(*gmode==5)
				printf("HI\n2:640*480\n");
			else
				printf("?\nUNKNOWN\n");
			break;
		case 3:
			printf("EGA:EGA");
			if(*gmode<1)
				printf("LO\n16:640*200\n");
			else if(*gmode==1)
				printf("HI\n16:640*350\n");
			else
				printf("?\nUNKNOWN\n");
			break;
		case 4:
			printf("EGA644:EGA644");
			if(*gmode<1)
				printf("LO\n16:640*200\n");
			else if(*gmode==1)
				printf("HI\n16:640*350\n");
			else
				printf("?\nUNKNOWN\n");
			break;
		case 5:
			printf("EGAMON:EGAMON");
			if(*gmode==0)
				printf("HI\n2:640*350\n");
			else
				printf("?\nUNKNOWN\n");
			break;
		case 6:
			printf("IBM8514:IBM8514");
			if(*gmode<1)
				printf("LO\n256:640*480\n");
			else if(*gmode==1)
				printf("HI\n256:1024*768\n");
			else
				printf("?\nUNKNOWN\n");
			break;
		case 7:
			printf("HERC:HERC");
			if(*gmode==0)
				printf("MONOHI\n2:720*348\n");
			else
				printf("?\nUNKNOWN\n");
			break;
		case 8:
			printf("ATT400:ATT400");
			if(*gmode<4)
				printf("C%d\nC%d:320*200\n",*gmode,*gmode);
			else if(*gmode==4)
				printf("MED\n2:320*200\n");
			else if(*gmode==5)
				printf("HI\n2:320*200\n");
			else
				printf("?\nUNKNOWN\n");
			break;
		case 9:
			printf("VGA:VGA");
			if(*gmode==0)
				printf("LO\n16:640*200\n");
			else if(*gmode==1)
				printf("MED\n16:640*350\n");
			else if(*gmode==2)
				printf("HI\n16:640*480\n");
			else
				printf("?\nUNKNOWN\n");
			break;
		case 10:
			printf("PC3270:PC3270");
			if(*gmode==0)
				printf("HI\n2:720*350\n");
			else
				printf("?\nUNKNOWN\n");
			break;
		case 0:
			printf("DETECT:\n");
			break;
		default:
			printf("UNKNOWN\n");
	}
}
void drawmat(char *mat,int matsize,int x,int y,int color)
{
	int i,j,k,n;
 	n=(matsize-1)/8+1;
 	for(j=0;j<matsize;j++)
  		for(i=0;i<n;i++)
   			for(k=0;k<8;k++)
    				if(mat[j*n+i]&(0x80>>k))
     					putpixel(x+i*8+k,y+j,color);
}
void drawlogo(int x,int y)
{
	char logo1[32][32]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF0,0x0F,0xF8,
	0x1F,0xE0,0x07,0xF8,0x1F,0xC0,0x03,0xF8,0x1F,0x80,0x01,0xF8,0x1F,0x00,0x00,0xF8,
	0x1E,0x00,0x00,0x78,0x1C,0x00,0x00,0x38,0x18,0x00,0x00,0x18,0x10,0x00,0x00,0x08,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x10,0x00,0x00,0x08,0x18,0x00,0x00,0x18,0x1C,0x00,0x00,0x38,0x1E,0x00,0x00,0x78,
	0x1F,0x00,0x00,0xF8,0x1F,0x80,0x01,0xF8,0x1F,0xC0,0x03,0xF8,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
	logo2[32][32]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,0xC0,
	0x00,0x91,0x8C,0x00,0x00,0x91,0x8C,0x00,0x00,0x91,0x8C,0x00,0x00,0x91,0x8F,0x00,
	0x00,0x91,0x89,0xC0,0x00,0x91,0x88,0x40,0x00,0x91,0x88,0x40,0x00,0x91,0x88,0x40,
	0x00,0x9F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x0A,0xA0,0x0A,0xA8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
	logo3[32][32]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xE0,0x07,0xF8,
	0x15,0x50,0x05,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
	logo4[32][32]={0x00,0x01,0x80,0x00,0x00,0x03,0xC0,0x00,0x00,0x07,0xE0,0x00,0x00,0x0F,0xF0,0x00,
	0x00,0x1F,0xF8,0x00,0x00,0x3F,0xFC,0x00,0x00,0x7F,0xFE,0x00,0x00,0xFF,0xFF,0x00,
	0x01,0xFF,0xFF,0x80,0x03,0xFF,0xFF,0xC0,0x07,0xFF,0xFF,0xE0,0x0C,0x00,0x00,0x30,
	0x1E,0x00,0x00,0x18,0x3F,0x26,0x31,0xFC,0x7F,0x26,0x31,0xFE,0xFF,0x26,0x30,0xFF,
	0x3F,0x26,0x30,0x3C,0x1F,0x26,0x32,0x18,0x0F,0x26,0x33,0x90,0x07,0x26,0x33,0x80,
	0x03,0x20,0x00,0x00,0x01,0xA0,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x7F,0xFE,0x00,
	0x00,0x3F,0xFC,0x00,0x00,0x1F,0xF8,0x00,0x00,0x0F,0xF0,0x00,0x00,0x07,0xE0,0x00,
	0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
	logo5[32][32]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x01,0x6E,0x73,0xE0,0x00,0x48,0x42,0x00,0x00,0x48,0x42,0x00,0x00,0x48,0x40,0x00,
	0xC0,0x48,0x46,0x03,0x60,0x48,0x45,0xA6,0x30,0x48,0x44,0x2C,0x18,0x48,0x44,0x38,
	0x0C,0x40,0x00,0x30,0x06,0x5F,0xFF,0xE0,0x03,0x00,0x00,0xC0,0x01,0x80,0x01,0x80,
	0x00,0xC0,0x03,0x00,0x00,0x60,0x06,0x00,0x00,0x30,0x0C,0x00,0x00,0x18,0x18,0x00,
	0x00,0x0C,0x30,0x00,0x00,0x07,0xE0,0x00,0x00,0x03,0xC0,0x00,0x00,0x01,0x80,0x00};
	drawmat(logo1,32,x,y,4);
	drawmat(logo2,32,x,y,0);
	drawmat(logo3,32,x,y,1);
	drawmat(logo4,32,x,y,7);
	drawmat(logo5,32,x,y,8);
}
#endif